package com.esms.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.esms.dao.DepartmentMapper;
import com.esms.dao.EmployeeMapper;
import com.esms.dao.GrandMapper;
import com.esms.po.Aassessment;
import com.esms.po.Department;
import com.esms.po.Employee;
import com.esms.po.Grand;
import com.esms.service.IEmployeeGrandServer;

@Service
public class EmployeeGrandServerImpl implements IEmployeeGrandServer {
	@Autowired
    private GrandMapper grandMapper = null;
	@Autowired
    private EmployeeMapper employeeMapper = null;
	@Autowired
    private DepartmentMapper departmentMapper = null;
	
    @Override
	public List<Grand> getEmployeeGrandList(int eId, String fEid) {
    	Employee employee = employeeMapper.selectByPrimaryKey(eId);
		int pId = employee.getpId();
		int dId = employee.getdId();
		String e_account = employee.geteAccount();
		if (pId == 3 || pId == 5 ) {
			if ("0".equals(fEid)) {
				return grandMapper.selectBypIdAnddId(pId, dId, e_account);
			} else {
				return grandMapper.selectBypIdAnddIdAndfEid(pId, dId, fEid, e_account);
			}
		}else if(pId == 4){
			Department department = departmentMapper.selectByPrimaryKey(dId);
			int sjId = department.getdGsid();
			if ("0".equals(fEid)) {
				return grandMapper.selectBypIdAnddIdkz(pId,sjId,e_account);
			} else {
				return grandMapper.selectBypIdAnddIdAndfEidkz(pId, sjId, fEid, e_account);
			}
		}else {
			return new ArrayList<Grand>();
		}
	}
    
    @Override
    public int updateGrandList(Grand grand) {
         return  grandMapper.updateBysId(grand); 
    
    }
    
    @Override
    public int deleteGrand(String aAuserid , String aDuserid) {
         return  grandMapper.deleteGrand(aAuserid, aDuserid);
    
    }
    
    @Override
    public int insertGrand(Aassessment aassessment) {
         return  grandMapper.insertGrand(aassessment); 
    
    }
}
